<template>
    <div id="opportunity">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item to="/">
                    <i class="iconfont icon-home nav-icon"></i>
                </el-breadcrumb-item>
                <el-breadcrumb-item class="no-active">销售机会管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-form :inline="true" stripe border :model="query">
                <el-form-item label="客户名称">
                    <el-input v-model="query.customerName" placeholder="客户名称"></el-input>
                </el-form-item>
                <el-form-item label="概要">
                    <el-input v-model="query.summary" placeholder="概要"></el-input>
                </el-form-item>
                <el-form-item label="联系人">
                    <el-input v-model="query.linkman" placeholder="联系人"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button-group>
                        <el-button icon="el-icon-search" type="primary" @click="searchBtn">查询</el-button>
                        <el-button
                            icon="el-icon-circle-plus-outline"
                            type="success"
                            @click="$router.push('/opportunity/new/`')"
                        >新建</el-button>
                        <el-button
                            icon="el-icon-phone-outline"
                            type="info"
                            @click="$message.info('敬请期待...');"
                        >帮助</el-button>
                    </el-button-group>
                </el-form-item>
            </el-form>
            <el-table :data="tableData" stripe>
                <el-table-column fixed prop="id" label="编号" width="50"></el-table-column>
                <el-table-column prop="customerName" label="客户名称" width="80"></el-table-column>
                <el-table-column prop="linkman" label="联系人" width="70"></el-table-column>
                <el-table-column prop="linkPhone" label="联系电话" width="120"></el-table-column>
                <el-table-column sortable prop="createTime" label="创建时间" width="180"></el-table-column>
                <el-table-column prop="summary" label="概要"></el-table-column>
                <el-table-column fixed="right" label="操作" width="240">
                    <template slot-scope="scope">
                        <el-button-group>
                            <el-button
                                icon="el-icon-s-custom"
                                size="mini"
                                type="primary"
                                @click="$router.push(`/opportunity/appoint/${scope.row.id}`)"
                            >指派</el-button>
                            <el-button
                                icon="el-icon-edit-outline"
                                size="mini"
                                type="warning"
                                @click="$router.push(`/opportunity/edit/${scope.row.id}`)"
                            >编辑</el-button>
                            <el-button
                                icon="el-icon-delete"
                                size="mini"
                                type="danger"
                                @click="handleDelete(scope.row)"
                            >删除</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            query: {
                customerName: '',
                summary: '',
                linkman: '',
                pageIndex: 1,
                pageSize: 10
            },
            tableData: [],
            pageTotal: 20
        };
    },
    methods: {
        searchBtn() {
            this.$api.opportunity.search(this.query).then(res => {
                this.tableData = res.data;
                this.pageTotal = res.count;
            });
        },
        handleDelete(row) {
            this.$confirm(`此操作将永久删除【 ${row.customerName} 】客户信息, 是否继续?`, '删除提醒', { type: 'warning' }).then(() => {
                this.searchBtn();
                this.$message.success('删除成功~');
            });
        },

        // 分页导航
        handlePageChange(val) {
            this.query.pageIndex = val;
            this.searchBtn();
        }
    },
    created() {
        this.searchBtn();
    }
};
</script>

<style>
</style>